package campus.aiit.ssl.service;

import campus.aiit.ssl.dao.DepartmentDao;
import campus.aiit.ssl.domain.model.Department;
import campus.aiit.ssl.manage.custom.dao.DaoProxy;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.PostConstruct;

@Service
public class DepartmentService {
    private DepartmentDao departmentDao;

    @Autowired
    public DepartmentService(DepartmentDao departmentDao){
        this.departmentDao = departmentDao;
    }

    @PostConstruct
    public void afterConstruct() {
        DaoProxy<DepartmentDao> proxy = new DaoProxy<>();
        departmentDao = proxy.getProxy(departmentDao);
    }

    public int insertSelective(Department record) {
        return departmentDao.insertSelective(record);
    }

    public int deleteByPrimaryKey(Long id) {
        return departmentDao.deleteByPrimaryKey(id);
    }

    public Department selectByPrimaryKey(Long id) {
        return departmentDao.selectByPrimaryKey(id);
    }

    public int updateByPrimaryKeySelective(Department record){
        return departmentDao.updateByPrimaryKeySelective(record);
    }

    public int insertByName(String name){return departmentDao.insertByName(name);}

    public Department[] getDepartments(){
        return departmentDao.selectBlocks();
    }
}
